﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace KnowlegeAssistant
{
    class GroupUtil
    {
        public static List<Group> GetAllGroups()
        {
            List<Group> groups = new List<Group>() { };
            DataTable groupstable = new DataTable();

            groupstable = DatabaseConnect.execSP("GetAllGroups").Tables[0];

            Group g = null;

            foreach (DataRow r in groupstable.Rows)
            {
                g = new Group((int)r["group_id"], r["name"].ToString(), r["group_number"].ToString(), (byte)r["course"]);
                groups.Add(g);
            }

            return groups;
        }

        public static Group GetGroup(int group_id)
        {
            Group g = null;
            DataTable table = DatabaseConnect.execSP("GetGroup", new List<string>() { group_id.ToString() }).Tables[0];
            g = new Group(
                (int)table.Rows[0]["group_id"], 
                table.Rows[0]["name"].ToString(), 
                table.Rows[0]["group_number"].ToString(), 
                (byte)table.Rows[0]["course"]
                );
            return g;
        }
    }
}
